home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE09 / CHARTFX / GRAPH.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-17  |  3.2 KB  |  94 lines

  1. unit Graph;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Buttons, ExtCtrls, StdCtrls, DB, DBTables, VBXCtrl,
  8.   ChartFx,       { Contained in C:\Delphi\Source\Samples }
  9.   Chart2fx;
  10.  
  11. type
  12.   TGraphForm = class(TForm)
  13.     ChartFX1: TChartFX;
  14.     DataSource1: TDataSource;
  15.     Query1: TQuery;
  16.     SQLEdit: TMemo;
  17.     Panel1: TPanel;
  18.     SQLExexBtn: TSpeedButton;
  19.     CloseBtn: TSpeedButton;
  20.     procedure SQLExexBtnClick(Sender: TObject);
  21.     procedure CloseBtnClick(Sender: TObject);
  22.   private
  23.     { Private declarations }
  24.   public
  25.     { Public declarations }
  26.   end;
  27.  
  28. var
  29.   GraphForm: TGraphForm;
  30.  
  31. implementation
  32.  
  33. {$R *.DFM}
  34.  
  35. procedure TGraphForm.SQLExexBtnClick(Sender: TObject);
  36. var
  37.  NumRecs : Integer;                  {- Data Counter                 -}
  38.  NumCols : Integer;                  {- Number of Columns in the Data-}
  39.  ColCntr : Integer;                  {- Index for the For Loop       -}
  40. begin
  41.  {-Assign Properties to TQuery & TDataSource Components at Run time  -}
  42.   DataSource1.DataSet := Query1;     {- Name of the TQuery Component -}
  43.   Query1.DatabaseName := 'DBDEMOS';  {- BDE Database Alias           -}
  44.   Query1.close;                      {- Close Any Pending Queries    -}
  45.   Query1.SQL.Clear;                  {- Clear Previous SQL Query Text-}
  46.   Query1.SQL.Add(SQLEdit.Text);      {- Pass the SQL Query Text      -}
  47.   Query1.Active := True;             {- Run The Query                -}
  48.  
  49.   NumRecs := Query1.RecordCount;     {- Count the Number of Records  -}
  50.                                      {- Found by the Query           -}
  51.   NumCols := Query1.FieldCount;{- Number of Fields in the DataSet    -}
  52.  
  53.   {- Fill Data  Assuming MultiColumns                                -}
  54.   for ColCntr := 0 to NumCols-2 do
  55.    begin
  56.   { Initialise ChartFx with NumberofColumns, Number of DataPoints     }
  57.     ChartFX1.OpenData[COD_VALUES] := makelong(NumCols-1,NumRecs);
  58.     ChartFX1.ThisSerie := ColCntr;   {- Tell ChartFx to expect Data  -}
  59.                                      {- For the Current Series       -}
  60.  
  61.     NumRecs := 0;                    {- Initialise the Data Counter  -}
  62.     Query1.First;
  63.     repeat
  64.       {- Fill Labels -}
  65.       ChartFX1.Legend[NumRecs] := Query1.Fields[0].AsString;
  66.       {- Fill Data Columns -}
  67.       ChartFX1.Value[NumRecs]  := Query1.Fields[ColCntr+1].AsFloat;
  68.       NumRecs := NumRecs + 1;        {- Advance the Data Counter     -}
  69.       Query1.Next;
  70.     until Query1.EOF;
  71.  
  72.     { Maximum Value for Y Axis  -  Can Set ChartFx behaviour at RunTime
  73.     ChartFX1.Adm[CSA_MIN] := 0;
  74.     Graph.ChartFX1.Adm[CSA_MAX] := MaxVal;                            }
  75.     { Graph Title's LEFT, Right, Top, Bottom                          }
  76.     ChartFX1.Title[CHART_LEFTTIT] := Query1.Fields[1].FieldName;
  77.     ChartFX1.Title[CHART_BOTTOMTIT] := Query1.Fields[0].FieldName;
  78.     ChartFX1.Title[CHART_RIGHTTIT] := 'Example of TQuery With ChartFx';
  79.     {Close The Data Channel For the current Series                    }
  80.     ChartFX1.CloseData[0] := ColCntr;
  81.   end;
  82.  
  83.   Query1.Active := False;           {- Close The Query              -}
  84.  
  85. end;
  86.  
  87.  
  88. procedure TGraphForm.CloseBtnClick(Sender: TObject);
  89. begin
  90.  Close;
  91. end;
  92.  
  93. end.
  94.